package com.anxin.registerManagement.controller;

import com.anxin.registerManagement.bean.jo.ClassRoomSearchJo;
import com.anxin.registerManagement.bean.persist.ClassRoom;
import com.anxin.registerManagement.service.ClassRoomService;
import com.anxin.registerManagement.util.Assert;
import com.anxin.registerManagement.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 叶前呈
 * @date 2022/1/30 14:48
 */
@Api(tags = "班级接口")
@RestController
@RequestMapping("/classrooms")
public class ClassRoomController {

    private static final Logger logger = LoggerFactory.getLogger(ClassRoomController.class);

    @Autowired
    ClassRoomService classRoomService;

    @ApiOperation("查询班级")
    @PostMapping("/search")
    public ResultUtil getClassRoomsList(@RequestBody ClassRoomSearchJo classRoomSearchJo) {
        logger.info("查询班级：{}", classRoomSearchJo);
        return ResultUtil.success(classRoomService.getClassRoomList(classRoomSearchJo));
    }

    @ApiOperation("添加班级")
    @PostMapping("/add")
    public ResultUtil addClassRoom(@Valid @RequestBody ClassRoom classRoom) {
        logger.info("添加班级：{}", classRoom);
        classRoomService.addClassRoom(classRoom);
        return ResultUtil.success();
    }

    @ApiOperation("修改班级")
    @PostMapping("/update")
    public ResultUtil updateClassRoom(@Valid @RequestBody ClassRoom classRoom) {
        logger.info("修改班级：{}", classRoom);
        Assert.notNull(classRoom.getId(), "班级id不能为空");
        classRoomService.updateClassRoom(classRoom);
        return ResultUtil.success();
    }

    @ApiOperation("删除班级")
    @PostMapping("/delete")
    public ResultUtil deleteClassRoom(@RequestParam("id") List<Integer> id) {
        logger.info("删除班级：{}", id);
        Assert.notNull(id, "班级id不能为空");
        classRoomService.deleteClassRoom(id);
        return ResultUtil.success();
    }

    @ApiOperation("获取所有班级")
    @GetMapping("/get")
    public ResultUtil getAllClassRoom() {
        return ResultUtil.success(classRoomService.getAllClassRoom());
    }

    @ApiOperation("获取所有班级，例如信息与计算科学182")
    @GetMapping("/getDetail")
    public ResultUtil getAllClassRoomDetail() {
        return ResultUtil.success(classRoomService.getAllClassRoomDetail());
    }

}
